From a086557ab80890472ad0512be8331c5a994dd24b Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 15 Feb 2015 19:29:38 +0100 Subject: [PATCH] [schema] Make column user_newtalk.user_id an unsigned int The primary key of the user table is an unsigned int, the column user_newtalk.user_id refer the id and should have the same typ to store the same values as the user table does. No pre-deployment activity necessary; no need to sync deployment and merge; can be done at any time (now or later) Bug: T77005 Change-Id: I641dc1fad0a5bb14815f55e0357243a562fd672b --- includes/db/DatabaseMysqlBase.php | 8 +++++++ includes/installer/MysqlUpdater.php | 23 +++++++++++++++++++ .../patch-user-newtalk-userid-unsigned.sql | 1 + maintenance/tables.sql | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 maintenance/archives/patch-user-newtalk-userid-unsigned.sql diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 458b286948..c1f2969d73 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -1201,6 +1201,7 @@ class MySQLField implements Field { $this->is_multiple = $info->multiple_key; $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple ); $this->type = $info->type; + $this->flags = $info->flags; $this->binary = isset( $info->binary ) ? $info->binary : false; } @@ -1250,6 +1251,13 @@ class MySQLField implements Field { return $this->is_multiple; } + /** + * @return int + */ + function flags() { + return $this->flags; + } + function isBinary() { return $this->binary; } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 81f563a578..eada44a918 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -270,6 +270,7 @@ class MysqlUpdater extends DatabaseUpdater { array( 'dropTable', 'hitcounter' ), array( 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ), array( 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ), + array( 'doUserNewTalkUseridUnsigned' ), ); } @@ -1062,4 +1063,26 @@ class MysqlUpdater extends DatabaseUpdater { 'Making iwl_prefix_title_from index non-UNIQUE' ); } + + protected function doUserNewTalkUseridUnsigned() { + if ( !$this->doTable( 'user_newtalk' ) ) { + return true; + } + + $info = $this->db->fieldInfo( 'user_newtalk', 'user_id' ); + if ( $info === false ) { + return true; + } + if ( ( $info->flags() & 32 /*MYSQLI_UNSIGNED_FLAG*/ ) ) { + $this->output( "...user_id is already unsigned int.\n" ); + + return true; + } + + return $this->applyPatch( + 'patch-user-newtalk-userid-unsigned.sql', + false, + 'Making user_id unsigned int' + ); + } } diff --git a/maintenance/archives/patch-user-newtalk-userid-unsigned.sql b/maintenance/archives/patch-user-newtalk-userid-unsigned.sql new file mode 100644 index 0000000000..a83e03b9d2 --- /dev/null +++ b/maintenance/archives/patch-user-newtalk-userid-unsigned.sql @@ -0,0 +1 @@ +ALTER TABLE /*_*/user_newtalk MODIFY user_id int unsigned NOT NULL default 0; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 112ac0534c..4433502c68 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -182,7 +182,7 @@ CREATE UNIQUE INDEX /*i*/ufg_user_group ON /*_*/user_former_groups (ufg_user,ufg -- CREATE TABLE /*_*/user_newtalk ( -- Key to user.user_id - user_id int NOT NULL default 0, + user_id int unsigned NOT NULL default 0, -- If the user is an anonymous user their IP address is stored here -- since the user_id of 0 is ambiguous user_ip varbinary(40) NOT NULL default '', -- 2.20.1